package org.xteam.engine;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Point;
import java.awt.image.BufferedImage;

public class FrameBuffer {

	private int width;
	private int height;
	private BufferedImage image;

	public FrameBuffer(int width, int height) {
		this.width = width;
		this.height = height;
		this.image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
	}

	public void drawLine(Point p1, Point p2) {
//		Graphics2D g2d = (Graphics2D)image.getGraphics();
//		g2d.setColor(Color.white);
//		g2d.drawLine(p1.x, p1.y, p2.x, p2.y);
		
		Bresenham.draw(p1.x, p1.y, p2.x, p2.y, new PixelBuffer() {

			@Override
			public void putPixel(int x, int y) {
				image.setRGB(x, y, 0xFFFFFF);
			}

			@Override
			public int getWidth() {
				return image.getWidth();
			}

			@Override
			public int getHeight() {
				return image.getHeight();
			}
		});
	}

	public int getWidth() {
		return width;
	}

	public int getHeight() {
		return height;
	}

	public Image getImage() {
		return image;
	}

	public void clear() {
		Graphics2D g2d = (Graphics2D)image.getGraphics();
		g2d.setColor(Color.black);
		g2d.fillRect(0, 0, width, height);
	}

}
